package com.gdth.thread;

import java.util.List;

import android.util.Log;

import com.gdth.bank.BankApplication;
import com.gdth.bank.bean.TbxxbBean;
import com.gdth.bank.presenter.SynchronizePresenter;
import com.gdth.bank.presenter.TAppCanshuPresenter;
import com.gdth.database.bean.TAppYh;

/**
 * 用于更新的同步数据
 * @author mac1
 *
 */
public class DownLoadThread {
	private static final String TAG = "DownLoadTimerTask";

	public static final int update_type_bm = 101;
	public static final int update_type_yh = 102;
	public static final int update_type_canshu = 103;
	public static final int update_type_cjkh = 104;
	
	private static class DownLoadHelper {
		public static final DownLoadThread instance = new DownLoadThread();
	}
	
	public static final DownLoadThread getInstance() {
		return DownLoadHelper.instance;
	}
	
	Thread mThread;
	
	int bm, canshu, yh, cjkh;
	
	public void DownLoadByBeans(List<TbxxbBean> mList) {
		if (mList != null) {
			for (TbxxbBean bean : mList) {
				//1部门，2用户，3参数
				int type = bean.getLx();
				if (type == 1) {
					this.bm = update_type_bm;
				}
				if (type == 2) {
					this.yh = update_type_yh;
				}
				if (type == 3) {
					this.canshu = update_type_canshu;
				}
				if (type == 4) {
					this.cjkh = update_type_cjkh;
				}
			}
			

		}
	}
	
	public void startDownload() {
		mThread = new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub

				downloadData();
			}
			
		});
		
		mThread.start();
	}
	
	private void downloadData() {
		// TODO Auto-generated method stub
		Log.e(TAG, "同步最新数据: "+System.currentTimeMillis());

		SynchronizePresenter presenter = new SynchronizePresenter();
		
//		if (bm == update_type_bm)
//			presenter.getAllBm();
//		if (canshu == update_type_canshu) {
//			TAppCanshuPresenter mTAppCanshuPresenter = new TAppCanshuPresenter();
//			mTAppCanshuPresenter.getCanshuOnline();
//		}
//		if (yh == update_type_yh) {
//			presenter.getUserData();
//		}
//		
//		if (cjkh == update_type_cjkh) 
//			presenter.getAllBfrj();
		//cyx修改
		TAppYh user = BankApplication.mInstance.getCurrentUser();
		TAppCanshuPresenter mTAppCanshuPresenter = new TAppCanshuPresenter();
//		String content="";
//		presenter.gethddj(content);
		mTAppCanshuPresenter.getjxgzhz(user.getZh());
		presenter.getAllBm();
		mTAppCanshuPresenter.getCanshuOnline();
		presenter.getUserData();
		presenter.getAllBfrj();
	}	
}
